//-----------------------------------------------------------------------
//<copyright file="BienBanKiemKeKhoBLL.cs
//Code gen by tool.
//</copyright>
//-----------------------------------------------------------------------
using System;
using PMS.Exceptions;
using System.Collections.Generic;
using PMS.DAL;
using PMS.Entity;
using System.Transactions;

namespace PMS.BLL
{
    public class BienBanKiemKeKhoBO : BaseBO
    {
        // Interface Instant Object
        private readonly IBienBanKiemKeKhoDAO bienbankiemkekhoInterfaceObject = null;
        private readonly ChiTietBienBanKiemKeKhoBO ChiTietBBKKKInterfaceObject = null;

        // Constructor
        public BienBanKiemKeKhoBO()
        {
            bienbankiemkekhoInterfaceObject = new DAL.ServiceFactory<IBienBanKiemKeKhoDAO>().CurrentDAL;
            ChiTietBBKKKInterfaceObject = new ChiTietBienBanKiemKeKhoBO();
        }

        #region BienBanKiemKeKho

        /// <summary>
        ///
        /// </summary>
        /// <param name="bienbankiemkekho"></param>
        public BienBanKiemKeKho CreateBienBanKiemKeKho(BienBanKiemKeKho bienbankiemkekho, ChiTietBienBanKiemKeKhos DetailList)
        {
            string newstring = bienbankiemkekho.MaBBKKK;
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    bienbankiemkekho = bienbankiemkekhoInterfaceObject.CreateBienBanKiemKeKho(bienbankiemkekho);
                    foreach (ChiTietBienBanKiemKeKho item in DetailList)
                    {

                        item.MaBBKKK = bienbankiemkekho.MaBBKKK;
                        ChiTietBBKKKInterfaceObject.CreateChiTietBienBanKiemKeKho(item);

                    }
                }
                catch (Exception ex)
                {
                    bienbankiemkekho.MaBBKKK = newstring;
                    throw BusinessException.GetException("Business Access CreateBienBanKiemKeKho Exception", ex);
                }
                scope.Complete();
            }
            return bienbankiemkekho;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="bienbankiemkekho"></param>
        public void UpdateBienBanKiemKeKho(BienBanKiemKeKho bienbankiemkekho, ChiTietBienBanKiemKeKhos DetailList)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    bienbankiemkekhoInterfaceObject.UpdateBienBanKiemKeKho(bienbankiemkekho);
                    ChiTietBBKKKInterfaceObject.DeleteChiTietBienBanKiemKeKhoByMaBBKKK(bienbankiemkekho.MaBBKKK);
                    foreach (ChiTietBienBanKiemKeKho item in DetailList)
                    {
                        item.MaBBKKK = bienbankiemkekho.MaBBKKK;
                        ChiTietBBKKKInterfaceObject.CreateChiTietBienBanKiemKeKho(item);

                    }
                }
                catch (Exception ex)
                {
                    throw BusinessException.GetException("Business Access UpdatePhieuNhapException", ex);
                }
                scope.Complete();
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="bienbankiemkekho"></param>
        public void DeleteBienBanKiemKeKho(BienBanKiemKeKho bienbankiemkekho)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    ChiTietBBKKKInterfaceObject.DeleteChiTietBienBanKiemKeKhoByMaBBKKK(bienbankiemkekho.MaBBKKK);
                    bienbankiemkekhoInterfaceObject.DeleteBienBanKiemKeKho(bienbankiemkekho);
                }

                catch (Exception ex)
                {
                    throw BusinessException.GetException("Business Access DeleteBienBanKiemKeKhoException", ex);
                }
                scope.Complete();
            }
        }

        /// <summary>
        ///
        /// </summary>
        public BienBanKiemKeKhos GetAllBienBanKiemKeKho()
        {
            try
            {
                return bienbankiemkekhoInterfaceObject.GetAllBienBanKiemKeKho();
            }
            catch (Exception ex)
            {
                throw BusinessException.GetException("Business Access GetAllBienBanKiemKeKho Exception", ex);
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="maBBKKK"></param>
        public BienBanKiemKeKho GetBienBanKiemKeKhoByID(string maBBKKK)
        {
            try
            {
                return bienbankiemkekhoInterfaceObject.GetBienBanKiemKeKhoByID(maBBKKK);
            }
            catch (Exception ex)
            {
                throw BusinessException.GetException("Business Access GetBienBanKiemKeKhoBy ID Exception", ex);
            }
        }

        #endregion
    }
}
